/**
 * Description:
 * Class Name:TreeSetTest
 * Date:2022/3/25 11:07
 *
 * @author LTisme
 * @version JAVA17
 */
package 疯狂Java讲义.第9章_泛型._9_3_类型通配符._9_3_3_设定类型通配符的下限;

import java.util.Comparator;
import java.util.TreeSet;

public class TreeSetTest {
    public static void main(String[] args) {
        // Comparator 的实际类型是TreeSet的元素类型的父类，满足要求
        TreeSet<String> ts1 = new TreeSet<>(new Comparator<Object>() {
            @Override
            public int compare(Object fst, Object snd) {
                return fst.hashCode() > snd.hashCode() ? 1 : fst.hashCode() < snd.hashCode() ? -1 : 0;
            }
        });

        TreeSet<String> ts2 = new TreeSet<>(new Comparator<String>() {
            @Override
            public int compare(String fst, String snd) {
                return fst.length() > snd.length() ? 1 : fst.length() < snd.length() ? -1 : 0;
            }
        });

        ts1.add("hello");
        ts1.add("wa");
        ts2.add("hello");
        ts2.add("wa");

        System.out.println(ts1);
        System.out.println(ts2);

    }
}
